﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MyBasicLib.Utilities;
using MyBasicLib.Utilities.Log;
using MyBasicLib.Data.ORMLiteNew;

namespace MyBasicLib.Test.Utilities
{
    [TestClass]
    public class IOCTest
    {
        [TestMethod]
        public void TestMethodSingleton1()
        {
            var ioc = IOC.DefaultContainer;
            var obj1 = ioc.Resolve<ILogger>();
            Assert.IsNotNull(obj1);
            Assert.AreEqual(obj1, ioc.Resolve<ILogger>());
        }
        [TestMethod]
        public void TestMethodSingleton2()
        {
            var ioc = IOC.DefaultContainer;
            var obj1 = ioc.Resolve<IDbQueryProvider>();
            Assert.IsNotNull(obj1);
            Assert.AreNotEqual(obj1, ioc.Resolve<IDbQueryProvider>());
        }
        [TestMethod]
        public void TestMethod3()
        {
            var ioc = IOC.GetContainer("1");
            ioc.Register<ILogger>(() => new FileLogger());
            Assert.AreNotEqual(ioc.Resolve<ILogger>(), ioc.Resolve<ILogger>());
        }
        [TestMethod]
        public void TestMethod4()
        {
            var ioc = IOC.GetContainer("2");
            ioc.Register<ILogger>(() => new FileLogger(), true);
            Assert.AreEqual(ioc.Resolve<ILogger>(), ioc.Resolve<ILogger>());
        } 
    }
}
